package org.lojzesframework.freeMarker.utils;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

import org.apache.taglibs.standard.lang.jstl.BooleanLiteral;

public abstract class FileUtils {
     public static boolean writeFile(String fileName,String content){
    	 BufferedWriter bufferedWriter = null;
    	 try {
    		 File file = new File(fileName);
    		 if(makerFile(file)){
    			 bufferedWriter = new  BufferedWriter(new OutputStreamWriter(new FileOutputStream(file,true)));
    			 bufferedWriter.write(content);
    		 }
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			 if(null != bufferedWriter){
				 try {
					bufferedWriter.close();
				} catch (IOException e) {
					e.printStackTrace();
				} 
			 }
		}
		return false;
    	 
     }
     public static boolean makerFile(File file){
    	 if(!file.exists()){
    		 try {
				return file.createNewFile();
			} catch (IOException e) {
				e.printStackTrace();
			}
    	 }else{
    	    file.delete();
    	    try {
				return file.createNewFile();
			} catch (IOException e) {
				e.printStackTrace();
			}
    	 }
    	 return false;
     }
     public static void main(String[] args) {
    	 FileUtils.writeFile("d:/test.java", "hello java");
	}
}
